PHP $array[0] in $string for JSON

Posted by user1907696 on Stack Overflow See other posts from Stack Overflow or by user1907696
Published on 2012-12-16T10:57:50Z Indexed on 2012/12/16 11:03 UTC
Read the original article Hit count: 81

Filed under:
|
|

I am trying to use PHP to make a JSON file. Part of the code is as follow

$array = array("hello", "world");
$string='{"person": [
                     {
                      "name":'$array[0];',
                      "age":'$array[1];'
                     }
                    ]
          }';

The file created. However, $array[0] and $array[1] doesn't return the values "hello" and "world" but as $array[0] and $array[1]

Any idea?

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays